using System;
using System.Collections.Generic;

namespace Chaotic.DataBase.DataAccess
{
	internal static class DataAccessCache
	{
		private static readonly Dictionary<string, Delegate> Dic = new Dictionary<string, Delegate>();

		public static bool SetCache(string key, Delegate value)
		{
			if (string.IsNullOrEmpty(key))
			{
				return false;
			}
			bool result = false;
			try
			{
				Dic[key] = value;
				result = true;
			}
			catch
			{
			}
			return result;
		}

		public static Delegate GetCache(string key)
		{
			if (string.IsNullOrEmpty(key))
			{
				return null;
			}
			if (!Dic.ContainsKey(key))
			{
				return null;
			}
			return Dic[key];
		}

		public static bool IsCacheExist(string key)
		{
			if (string.IsNullOrEmpty(key))
			{
				return false;
			}
			return Dic.ContainsKey(key);
		}

		public static void RemoveCache(string key)
		{
			if (!string.IsNullOrEmpty(key) && Dic.ContainsKey(key))
			{
				Dic.Remove(key);
			}
		}
	}
}